public class Date {
    public int year;
    public int month;
    public int day;

    public static void main(String[] args) {
        Date D=new Date();
        System.out.println(D.year);
        System.out.println(D.month);
        System.out.println(D.day);              //成员变量未初始化时，java会默认初始化（int类型会初始化为0）
    }
}
public class Date {
    public int year;
    public int month;
    public int day;
public Date(int year,int month,int day){
    this.year=year;
    this.month=month;
    this.day=day;
}
public void printDate(){
        System.out.println(year+"/"+month+"/"+day);
    }
    public static void main(String[] args) {
        Date D=new Date(2025,03,11);
        D.printDate();
    }
}
public class Date {
    public int year;
    public int month;
    public int day;              //上述Date类中，没有定义任何构造方法，编译器会默认生成一个不带参数的构造方法
                                 //打印结果为0/0/0
    public void printDate(){
        System.out.println(year+"/"+month+"/"+day);
    }
    public static void main(String[] args) {
        Date D=new Date();
        D.printDate();
    }
}
/public class Date {
    public int year;
    public int month;
    public int day;
public Date(int year,int month,int day){
    this.year=year;
    this.month=month;
    this.day=day;
}                                              //这时编译器会报错，因为Date类中已经定义了带三个参数的构造方法，编译器不在生成“不带参数的构造方法”
public void printDate(){
        System.out.println(year+"/"+month+"/"+day);
    }
    public static void main(String[] args) {
        Date D=new Date();
        D.printDate();
    }
}
public class Date {
    public int year;
    public int month;
    public int day;
public Date(int year,int month,int day){
    this.year=year;
    this.month=month;
    this.day=day;
}
public Date(){
    this(2025,03,11);//构造方法中，可以通过this()调用其他构造方法来简化代码
}
public void printDate(){
        System.out.println(year+"/"+month+"/"+day);
    }
    public static void main(String[] args) {
        Date D=new Date();
        D.printDate();
    }
}
